<%@ page import="java.util.Map" %>
<%@ page import="cn.dgut.Entity.Student" %>
<%@ page import="cn.dgut.Utils.JDBCUtils" %>
<%@ page import="java.util.List" %>
<%@ page import="cn.dgut.Entity.Course" %>
<%@ page import="cn.dgut.Entity.Teacher" %>
<%@ page import="cn.dgut.Entity.Select_Course" %><%--
  Created by IntelliJ IDEA.
  User: HP
  Date: 2019/6/20
  Time: 13:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    Map<String,String> login = (Map<String, String>) request.getSession().getAttribute("isFrontLogin");
    int user_id;
    int loginFlag=0;
    if(login!=null){
        loginFlag=1; //已经登录
        user_id = Integer.parseInt(login.get("id"));
    }else {
        user_id = -1;
    }
    Student stu = new Student();
    stu = (Student) new JDBCUtils().queryOneData("Student",user_id);
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="robots" content="all,follow">
    <title>WeIn--个人信息</title>
    <link rel="shortcut icon" href="backstage/img/logo-title.png">
    <!-- global stylesheets -->
    <!--<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed" rel="stylesheet">-->
    <link rel="stylesheet" href="backstage/css/bootstrap.min.css">
    <link rel="stylesheet" href="backstage/css/course.css">
    <link rel="stylesheet" href="backstage/css/font-awesome.min.css">
    <link rel="stylesheet" href="backstage/css/font-icon-style.css">
    <link rel="stylesheet" href="backstage/css/style1.min.css">

    <link rel="stylesheet" href="backstage/css/sucaijiayuan.css">
    <link rel="stylesheet" href="backstage/css/style.default.css" id="theme-stylesheet">

    <!-- Core stylesheets -->
    <link rel="stylesheet" href="backstage/css/style.css">
    <link rel="stylesheet" href="backstage/css/main.css">
</head>
<body>
<header class="header">
    <nav class="navbar navbar-expand-lg" style="background:none;box-shadow: 0 0 0 0;">
        <div class="container">
            <div class="navbar-holder d-flex align-items-center justify-content-between">
                <div class="navbar-header">
                    <a href="index.jsp" class="navbar-brand">
                        <div class="brand-text brand-big hidden-lg-down"><img src="backstage/img/logo.png" alt="Logo" class="logo-img"></div>
                        <div class="brand-text brand-small"><img src="backstage/img/logo-min.png" alt="Logo" style="height: 30px;width:30px;margin-left: 5px;"></div>
                    </a>
                </div>
            </div>
            <ul class="nav-menu list-unstyled d-flex flex-md-row align-items-md-center">
                <li class="nav-item d-flex align-items-center">
                    <a class="nav-link" href="index.jsp">首页</a>
                </li>
                <li class="nav-item d-flex align-items-center">
                    <a class="nav-link" href="Courses.jsp">相关课程</a>
                </li>
                <li class="nav-item d-flex align-items-center">
                    <a class="nav-link" href="Teachers.jsp">师资力量</a>
                </li>
                <li class="nav-item d-flex align-items-center">
                    <a class="nav-link" href="SudentWorks.jsp">学员作品</a>
                </li>
                <li class="nav-item d-flex align-items-center" style="margin-right: 70px;">
                    <a class="nav-link" href="Recruit.jsp">人才招聘</a>
                </li>
                <%
                    if(loginFlag==0){
                %>
                <li class="nav-item d-flex align-items-center">
                    <a class="nav-link" href="login.html">登录</a>
                </li>
                <li class="nav-item d-flex align-items-center">
                    <a class="nav-link" href="register.html">注册</a>
                </li>
                <%
                }else {
                %>
                <li class="nav-item d-flex align-items-center">
                    <a class="nav-link" href="show.jsp"><%=login.get("name")%></a>
                </li>
                <li class="nav-item d-flex align-items-center">
                    <a class="nav-link" href="/logoutServlet">注销</a>
                </li>
                <%
                    }
                %>
                <!--<li class="nav-item dropdown"><a id="profile" class="nav-link logout" data-target="#" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><img src="img/avatar-1.jpg" alt="..." class="img-fluid rounded-circle" style="height: 30px; width: 30px;"></a>
                    <ul aria-labelledby="profile" class="dropdown-menu profile">
                        <li>
                            <a rel="nofollow" href="#" class="dropdown-item d-flex">
                                <div class="msg-profile"> <img src="backstage/img/avatar-1.jpg" alt="..." class="img-fluid rounded-circle"></div>
                                <div class="msg-body">
                                    <h3 class="h5">Steena Ben</h3><span>steenaben@Businessbox.com</span>
                                </div>
                            </a>
                            <hr>
                        </li>
                        <li>
                            <a rel="nofollow" href="profile.html" class="dropdown-item">
                                <div class="notification">
                                    <div class="notification-content"><i class="fa fa-user "></i>个人信息</div>
                                </div>
                            </a>
                        </li>
                        <li>
                            <a rel="nofollow" href="profile.html" class="dropdown-item">
                                <div class="notification">
                                    <div class="notification-content"><i class="fa fa-power-off"></i>退出</div>
                                </div>
                            </a>
                        </li>
                    </ul>
                </li>-->
            </ul>
        </div>
    </nav>
</header>
<div class="m-header-banner m-images-show" style="margin-top: -74px;">
    <section class="am-container am-text-center">
        <hgroup>
            <img src="backstage/img/<%=stu.getStudent_img()%>" style="width: 80px;height: 80px;border-radius: 50%;" alt="老师头像">
            <h2 style="color:#FFF;" id=""><%=stu.getStudent_name()%></h2>
            <br>
        </hgroup>
    </section>
</div>
<div class="am-container">
    <article class="m-mn-box m-images-container" style="margin-top: -40px;box-shadow: 0 5px 10px 0 rgba(0,0,0,0.1);padding-left: 5%;">
        <section>
            <h2 style="margin-left: -42px;margin-bottom: 30px;">个人信息：<a style="margin-left: 30px;" title="修改个人信息" id="userName" data-name="<%=stu.getStudent_name()%>" data-toggle="modal" data-target="#myModal" ><i class="fa fa-pencil" aria-hidden="true"></i></a></h2>
            <p>电话：<%=stu.getStudent_phone()%></p>
            <p>邮箱：<%=stu.getStudent_email()%></p>
            <p>学历：<%=stu.getSlevel()%></p>
            <p>VIP：<%=stu.getIsVip()%></p>
            <h2 style="margin-left: -42px;margin-bottom: 30px;">已报名的课程信息：</h2>
            <div class="_1Ifxn">
            <%
                if(user_id>0){
                    JDBCUtils utils = new JDBCUtils();
                    List courses = utils.queryAllData("Select_Course");
                    for (int i = 0; i < courses.size(); i++) {
                        Select_Course sc = (Select_Course) courses.get(i);
                        if(sc.getSid()==user_id){
                            Course temp = (Course) utils.queryOneData("Course",sc.getCourse_id());
                            Teacher tea = (Teacher) utils.queryOneData("Teacher",temp.getTid());
                            String sql = "select * from Select_Course where course_id = "+temp.getCourse_id();
                            int count = utils.count(sql,0);//报名人数
            %>

                            <div class="_2i6ze" style="margin-right: 20px;margin-top: 20px;">
                                <p style="margin-top: 10px;">报名时间：<%=sc.getTime()%></p>
                                <div class="_31FyG">
                                    <div class="_2J_BY">
                                        <a href="showCourse.jsp?id=<%=temp.getCourse_id()%>" class="XJp9n">
                                            <img src="img/2540136.png" alt="course">
                                            <div style="color:#FFF;position: absolute;left: 50%;top: 50%;transform: translate(-50%,-50%);font-size: 19px;width: 190px;text-align: center;">
                                                <%=temp.getCourse_name()%>
                                            </div>
                                        </a>
                                    </div>
                                    <div class="lZXHy">
                                        <a href="showCourse.jsp?id=<%=temp.getCourse_id()%>" class="_3EYtn"><%=temp.getCourse_name()%></a>
                                        <div class="ijgi2" style="margin-top: 5px;">
                                            <span style="margin-bottom: 3px;">主讲师：<a href="showTeacher.jsp?id=<%=tea.getTeacher_id()%>"><%=tea.getTeacher_name()%></a></span><br>
                                            <span class="_5o30w">报名人数：<em><%=count%></em></span>
                                            <span class="_1IbSZ">￥：<%=temp.getCourse_pay()%></span>
                                        </div>
                                    </div>
                                </div>
                            </div>
            <%
                        }
                    }
                }
            %>
            </div>
        </section>
    </article>
</div>
<footer class="m-footer" style="margin-top:20px;z-index:12;position:relative;padding-bottom: 40px;">
    <div class="am-container">
        <section style="padding-bottom:10px;" class="am-g m-footer-container">
            <section class="am-u-sm-12 am-u-md-6 foot-font">
                <img width="100%" src="img/u360.png">
                <p>东莞尾音信息科技有限公司，旗下有尾音教育等品牌，在东莞松山湖设立尾音软件实训基地，由8年以上资深教育经验php讲师牵头，一线开发工程师组成的团队，针对不同学员采取不同的教学方案。全心全意为学员服务，提供最专业的就业培训，专注于为企业输送最专业的人才</p>
                <p style="margin-bottom:0">地址：东莞市松山湖生产力大厦南座313-317</p>
                <p style="margin-top:0">电话：0769 - 26620567 </p>
            </section>
            <section style="height: 350px; background: rgb(252, 249, 242); cursor: url(&quot;http://webapi.amap.com/theme/v1.3/openhand.cur&quot;), default;" id="wein-map" class="am-u-sm-12 am-u-md-6 amap-container">

                <object style="display: block; position: absolute; top: 0; left: 0; height: 100%; width: 100%; overflow: hidden; pointer-events: none; z-index: -1;" type="text/html" data="about:blank"></object><div class="amap-maps"><div class="amap-drags" style=""><div class="amap-layers" style="transform: translateZ(0px);"><div class="amap-markers" style="position: absolute; z-index: 120; top: 175px; left: 300px;"><div class="amap-marker" style="top: -31px; left: -9px; z-index: 100; transform: rotate(0deg); transform-origin: 9px 31px; display: block;"><div class="amap-icon" title="东莞松山湖生产力大厦南区313-317" style="position: absolute; width: 19px; height: 33px; opacity: 1;"><img src="http://webapi.amap.com/theme/v1.3/markers/b/mark_bs.png" style="width: 19px; height: 33px; top: 0px; left: 0px;"></div></div></div><canvas class="amap-labels" draggable="false" width="1200" height="700" style="position: absolute; z-index: 99; height: 350px; width: 600px; top: 0px; left: 0px;"></canvas><canvas class="amap-layer" width="750" height="437" style="position: absolute; z-index: 0; transform-origin: 375px 218.5px; transform: scale3d(0.8, 0.8, 1); top: -44px; left: -75px; height: 437px; width: 750px;"></canvas></div><div class="amap-overlays" style=""></div></div></div><div style="display: none;"></div><div class="amap-controls"></div><a class="amap-logo" href="http://gaode.com" target="_blank" style="display: block;"><img src="http://webapi.amap.com/theme/v1.3/logo@2x.png"></a><div class="amap-copyright" style="display: none; visibility: visible;"><!--v1.4.4--> © 2019 AutoNavi <span class="amap-mcode">- GS(2018)1709号</span></div></section>
            <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.4.4&amp;key=369d3223bc0e3feafc9c12c69bbbd5f7"></script>
            <script>
                var map = new AMap.Map('wein-map', {
                    center: [113.887971,22.930962],
                    zoom: 15
                });
                marker = new AMap.Marker({
                    position:[113.887971,22.930962],
                    animation:"AMAP_ANIMATION_DROP",
                    map:map,
                    title:"东莞松山湖生产力大厦南区313-317"
                });
            </script>
        </section>
    </div>
</footer>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">
                    修改个人信息
                </h4>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
            </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="">用户名:</label>
                        <input type="text" name="name"  class="form-control login_input" placeholder=" 用户名" value="<%=stu.getStudent_name()%>"/>
                        <span id="s_2" style="display: none;"></span>
                    </div>
                    <div class="form-group">
                        <label for="">密码:</label>
                        <input type="password" name="password" class="form-control login_input" placeholder=" 密码" value="<%=stu.getStudent_passwd()%>"/>
                    </div>
                    <div class="form-group">
                        <label for="">手机号码:</label>
                        <input type="text" name="number"  class="form-control login_input" placeholder=" 手机号码" value="<%=stu.getStudent_phone()%>"/>
                        <span id="s_0" style="display: none;"></span>
                    </div>
                    <div class="form-group">
                        <label for="">邮箱:</label>
                        <input type="email" name="email"  class="form-control login_input" placeholder=" 邮箱" value="<%=stu.getStudent_email()%>"/>
                    </div>
                    <div class="form-group">
                        <label for="">学历:</label>
                        <input type="text" name="level"  class="form-control login_input" placeholder=" 学历" value="<%=stu.getSlevel()%>"/>
                    </div>
                    <div class="form-group" id="tips">

                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                    <button type="submit" id="btn-submit" class="btn btn-primary">
                        提交
                    </button>
                </div>
        </div>
    </div>
</div>
</body>
</html>
<script src="backstage/js/jquery.min.js"></script>
<script src="backstage/js/popper/popper.min.js"></script>
<script src="backstage/js/tether.min.js"></script>
<script src="backstage/js/bootstrap.min.js"></script>
<script>
    //判断字符是否为空的方法
    function notEmpty(obj){
        if(typeof obj == "undefined" || obj == null || obj == ""){
            return false;
        }else{
            return true;
        }
    }
    $(function () {
        var tips;
        var isRight = 1;
        $('input[name="name"]').blur(function () {
            var new1 = $(this).val();
            var old = document.getElementById("userName").dataset.name;
            console.log(new1);
            console.log(old);
            if(notEmpty(new1)){
                $.get("/CheckChangeInfo", {old: old, new1: new1}, function (data) {
                    var span = $("#s_2");
                    var flag = data.exsit;
                    span.css("color", "#000");
                    span.css("display", "inline");
                    if (flag == 1) {
                        isRight = 0;
                        span.html("该用户名太受欢迎啦！请换一个");
                    } else {
                        isRight = 1;
                        span.html("用户名可用")
                    }
                });
            }

        });


        $('input[name="number"]').blur(function () {
            var phone_number = $(this).val();
            $("#s_0").css("color","#000");
            $("#s_0").css("display","inline");
            if(phone_number.length != 11){
                $("#s_0").html("号码输入错误！！！");
                isRight = 3;
                return;
            }else {
                $("#s_0").html("");
                isRight = 1;
            }
        });

        $("#btn-submit").click(function () {
            var input = $(".login_input");
            if(isRight==1){
                //全部数据都不为空时，才发送数据
                if (notEmpty(input.eq(0).val()) && notEmpty(input.eq(1).val()) && notEmpty(input.eq(2).val()) && notEmpty(input.eq(3).val()) && notEmpty(input.eq(4).val())) {
                    $.ajax({
                        type: 'GET',
                        url: '/ModifyStudent',
                        data: {
                            user: input.eq(0).val(),
                            passwd: input.eq(1).val(),
                            phone: input.eq(2).val(),
                            email: input.eq(3).val(),
                            level: input.eq(4).val()
                        },
                        contentType: 'text/json,charset=utf-8',
                        dataType: 'json',
                        success: function (data) {
                            var flag = data.flag;
                            if (flag == 1) {
                                tips = "修改成功！！";
                                $("#tips").text(tips);
                                $("#myModal").click(function () {
                                    location.reload();
                                });

                            } else if (flag == 0) {
                                tips = "修改失败！！输入可能有错误";
                                $("#tips").text(tips);
                            }else {
                                alert("服务器错误！！");
                            }
                        }
                    });
                }else {
                    $("#tips").text("所有的输入都不能为空！！！请检查一下");
                }
            }else if(isRight==2){
                tips = "手机号输入错误！！";
                $("#tips").text(tips);
            } else if(isRight==0){
                tips = "用户名已经被注册！！请换一个吧";
                $("#tips").text(tips);
            }else {
                tips = "有些信息输入错误！！请检查一下";
                $("#tips").text(tips);
            }
        });
    });
</script>